<?php
defined('BY_JYA') or exit('error');
$_RQ['op']=$_RQ['op']?$_RQ['op']:'main';
$return=array();
if($_RQ['mid']){
	$mid=intval($_RQ['mid']);
	$this->session('agent_id',$mid);
}else{
	$this->model()->check_agent();
	$mid=$_SESSION['uid'];
}

if($_RQ['op']=='main'){
	$return['sharedata']=array(
		'title'=>$myshop['title']?$myshop['title']:'小店',
		'desc'=>$myshop['desc'],
		'link'=>custom_url('jy_friends_shop/mayshop/main/mid='.$mid,true),
		'imgUrl'=>tomedia($myshop['logo']),
	);
	$myshop=$this->pdo_get('shop',array('mid'=>$mid,'uniacid'=>$_SESSION['uniacid']));
	$agent_member=pdo_get('core_members',array('id'=>$mid),array('nickname','avatar'));
	if(!$myshop['logo']){
		$myshop['logo']=$agent_member['avatar'];
	}
	if(!$myshop['title']){
		$myshop['title']=$agent_member['nickname'];
	}
	$return['myshop']=$myshop;
	exi($return);
}
if($_RQ['op']=='list'){
	$params=array('uniacid'=>$_SESSION['uniacid'],'mid'=>$mid);
	if($_RQ['title']){
		$params['title like']='%'.trim($_RQ['title']).'%';
	}
	//按点赞数排序作品
	$psize=100;
	$pindex=intval($_RQ['page'])?:1;
	if($pindex>1){
		//一次性获取，如果尝试获取第二页，直接返回空
		exi('none');
	}
	$parameter=array(
		'params'=>$params,		
	);
	$list=$this->pdo_getlist('goods',$parameter,$total);
	if(!$list){
		exi('none');
	}else{
		foreach($list as $key=>&$item){
			$goods=pdo_get('jy_weishop_goods',array('id'=>$item['goodsid'],'status'=>1),array('title','image','total'));
			if(!$goods){
				unset($list[$key]);
				continue;
			}
			$item=array_merge($goods,$item);
		}
	}
	exi($list);
}
?>